<?php

//单页
class singlepageMod extends commonMod
{
    public function __construct()
    {
        parent::__construct();

    }


    //单页
    public function index()
    {
        $id = intval($_GET[0]);
        if (empty($id)) {
            $this->error404();
        }

        $info = $this->model->table('channel')->where('id=' . $id)->find(); //读取栏目信息
        $cont = $this->model->table('channel_data')->where('cid=' . $id)->find(); //查询这个栏目的内容
        $content = $cont['content'];
        $parent_info = $this->model->table('channel')->where('id=' . $info['pid'])->find(); //查询这个栏目的上级栏目信息
        if (empty($parent_info)) {
            $parent_info = array("id" => "0", "pid" => "0", "mid" => "0", "name" => "无上级栏目");
        }

        $nav=$this->nav_cid($info['id']); //位置导航

        $replace = $this->model->field('*')->table('plus_replace')->select(); //读取内容替换
        if (!empty($replace)) {
            $str=$content;
            foreach ($replace as $key => $export) {
                $str = preg_replace('/(<a.*?>\s*)(.*'.$export[key].'.*)(\s*<\/a>)/isu', '${2}', $content,$export['num']);
                $content = preg_replace('/'.$export[key].'/isu',$export['content'], $str,$export['num']);
            }
        }

        if($this->config['URL_HTML_MODEL']==1){
			$content_url = __APP__ . '/'.$info['pinyin'].'/index-{page}.html'; //分页基准网址
		}
		if($this->config['URL_HTML_MODEL']==2){
			$content_url =module('label')->getcurl($info['id']) . '/index-{page}.html'; //分页基准网址
		}
		
		
        $page = new Page();
        $content = $page->contentPage(html_out($content), $separator = "<hr style=\"page-break-after:always;\" class=\"ke-pagebreak\" />",
        $url = $content_url, $pageBarNum = 10, $mode = 1); //文章分页

        $top=array_reverse($nav);//获取顶级栏目信息
		$top_id=$top[0]['id'];
		$top_info = $this->model->table('channel')->where('id=' . $top_id)-> find(); //顶级栏目信息

        $this->assign('top_info', $top_info); //顶级栏目信息
		
		$this->assign('top_id', $top_id); //顶级栏目ID
		$this->assign('info', $info); //页面信息
        $this->assign('content', $content['content']); //内容数据
        $this->assign('page', $content['page']); //分页
        $this->assign('parent_info', $parent_info); //上级栏目信息
        $this->assign('nav', array_reverse($nav)); //位置导航
        
        if($this->config['LANG_OPEN']==1){
        $this->display(__LANG__.'/'.$info['tpl_list']);
        }else{
        $this->display($info['tpl_list']);
        }

    }


}

?>